package com.fm.service.impl;

import com.fm.common.ResultResponse;
import com.fm.dao.OrderMapper;
import com.fm.pojo.Order;
import com.fm.service.IOrderService;
import com.fm.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service("orderService")
public class OrderServiceImpl implements IOrderService {
    private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
    @Autowired
    private OrderMapper orderMapper;

    public int checkOrderDays(String userId){
        Order order=orderMapper.selectByUserId(userId);
        int days=0;
        if(order!=null){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try{
                Date date = format.parse(format.format(new Date()));
                days=TimeUtil.differentDays(date,order.getCloseTime());
            }catch (Exception e){
                logger.error(e.getStackTrace().toString());
            }
        }
        return days;
    }
}
